import Vue from "vue";
import { getSystemUserListMock } from "@/config/system/user";
import Vuex from "vuex";
Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    username: "",
    password: "",
    users: getSystemUserListMock.data.systemUser,
  },
  actions: {
    login({ commit }, user) {
      commit("login", user);
    },
  },
  mutations: {
    login(state, { username, password }) {
      state.username = username;
      state.password = password;
    },
    loginout(state) {
      state.username = "";
      state.password = "";
    },
  },
  getters: {
    getUser: (state) => {
      return state.users.find(
        (user) =>
          user.userAccount === state.username &&
          user.password === state.password
      );
    },
  },
});

export default store;
